package br.com.portal.fitness.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import br.com.portal.fitness.enums.EStatus;
import br.com.portal.fitness.enums.ETipoUsuario;

/**
 *
 * @author rjulio
 */
@Entity
@Table(name = "USUARIO")
@NamedQueries({
	@NamedQuery(name = Usuario.FIND_ALL, query = "SELECT b FROM Usuario b")
})

public class Usuario implements Serializable{

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public static final String FIND_ALL = "Usuario.findAll";
    public static final String FIND_BY_TIPO = "Usuario.findByTipo";
    public static final String FIND_BY_LOGIN = "Usuario.findByLogin";

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id_usuario")
    private Integer id;

    @Column(name = "nome", length = 60)
    private String nome;

    @Column(name = "email", length = 60)
    private String email;

    @Enumerated(EnumType.ORDINAL)
    private EStatus status;

    @Column(name = "matricula")
    private Integer matricula;

    @Column(name = "funcao", length = 30)
    private String funcao;

    @Column(name = "departamento", length = 30)
    private String departamento;

    @OneToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, orphanRemoval = true)
    @JoinColumn(name = "senha_id")
    private Senha senha;

   
    @ManyToMany
    @JoinTable(
            name = "USUARIO_PERFIL",
            joinColumns
            = @JoinColumn(name = "id"),
            inverseJoinColumns
            = @JoinColumn(name = "id_perfil" ))
    private List<Perfil> perfis;
    
    @Column
    private String cpf;
    
	@Temporal(TemporalType.DATE)
	@Column(name = "ultimo_acesso")
	private Date ultimoAcesso;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public EStatus getStatus() {
		return status;
	}

	public void setStatus(EStatus status) {
		this.status = status;
	}

	public Integer getMatricula() {
		return matricula;
	}

	public void setMatricula(Integer matricula) {
		this.matricula = matricula;
	}

	public String getFuncao() {
		return funcao;
	}

	public void setFuncao(String funcao) {
		this.funcao = funcao;
	}

	public String getDepartamento() {
		return departamento;
	}

	public void setDepartamento(String departamento) {
		this.departamento = departamento;
	}

	public Senha getSenha() {
		return senha;
	}

	public void setSenha(Senha senha) {
		this.senha = senha;
	}

	public List<Perfil> getPerfis() {
		return perfis;
	}

	public void setPerfis(List<Perfil> perfis) {
		this.perfis = perfis;
	}

	public String getCpf() {
		return cpf;
	}

	public void setCpf(String cpf) {
		this.cpf = cpf;
	}

	public Date getUltimoAcesso() {
		return ultimoAcesso;
	}

	public void setUltimoAcesso(Date ultimoAcesso) {
		this.ultimoAcesso = ultimoAcesso;
	}  
    }
